package cn.yllr.tomgxianghui.controller.admin;

import cn.yllr.tomgxianghui.entity.Raw;
import cn.yllr.tomgxianghui.entity.User;
import cn.yllr.tomgxianghui.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class Admin_UserController {
    @Resource
    UserService userService;
    //用户列表
    @RequestMapping("/toViewUser")
    public String toViewUser(Model model){
        List<User> users=userService.queryAll();
        model.addAttribute("users",users);
        return "admin/user-list";
    }
    @RequestMapping("/deleteUser/{account}")
    public String deleteUser(@PathVariable("account")String account){
        userService.deleteById(account);
        return "redirect:/toViewUser";
    }
    //搜索用户
    @RequestMapping("/searchUser/{account}")
    public String searchDishes(@PathVariable("account")String account,Model model){
        User user=userService.queryById(account);
        model.addAttribute("user",user);
        return "admin/search-user";
    }
}
